<template>
  <div>
<!--    <h1>这里是Index</h1>-->

<!--    <div>-->
      <el-header>
        <h1>欢迎来到MBTI人格测试</h1>
      </el-header>
<!--    </div>-->

    <el-carousel :interval="4000" type="card" height="500px" ref="carousel">
      <el-carousel-item v-for="item in imagebox" :key="item.id" style="height: 500px; width: 896px">
        <router-link :to="item.pathUrl" tag="div">
          <div>
            <!--      <img :src="item.idView" class="image" @click="tohome">-->
            <img :src="item.idView" class="image" style="height: 500px; width: 896px">
            <h3 text="2xl" justify="center">{{ item }}</h3>
          </div>
        </router-link>
      </el-carousel-item>
    </el-carousel>

  </div>
</template>

<script>

import path1 from '../views/student/path1'
import path2 from '../views/student/path2'
import path3 from '../views/student/path3'
import path4 from '../views/student/path4'

export default {
  name: "Index",

  components:{
    path1,
    path2,
    path3,
    path4
  },
  data() {
    return {
      imagebox: [
        {id: 0, idView: require('../image/page1.png'),pathUrl:"/student/path1"},
        {id: 1, idView: require('../image/page2.png'),pathUrl: "/student/path2"},
        {id: 2, idView: require('../image/page3.png'),pathUrl: "/student/path3"},
        {id: 3, idView: require('../image/page4.png'),pathUrl: "/student/path4"}

        // {id: 0, idView: require('../image/jellyfish.jpg'),link:'/Menu'},
        // {id: 1, idView: require('../image/wall.jpg'),link: '/Role'},
        // {id: 2, idView: require('../image/fox.jpg'),link: '/User'},
        // {id: 3, idView: require('../image/flower.jpg'),link: '/SideMenu'}
      ],
      screenWidth: 0
    }
  },

  created()
  {
    console.log("主页面")
  },

  methods:{

    linkTo(){
      let activeIndex = this.$refs.carousel.activeIndex
      this.$router.push(this.imagebox[activeIndex].link)
    },


    setSize:function () {
      // 通过浏览器宽度(图片宽度)计算高度
      this.bannerHeight = 400 / 1920 * this.screenWidth;
    },
  },
  mounted() {
    // 首次加载时,需要调用一次
    this.screenWidth =  window.innerWidth;
    this.setSize();
    // 窗口大小发生改变时,调用一次
    window.onresize = () =>{
      this.screenWidth =  window.innerWidth;
      this.setSize();
    }
  },


}
</script>

<style scoped>

.el-carousel__item h3 {
  color: #475669;
  opacity: 0.75;
  line-height: 200px;
  margin: 0;
  text-align: center;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}

img{
  width: 1000px;
  height: 500px;
}

</style>